package com.example.myui.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.example.myui.R;
import com.example.myui.adapter.LeftAdapter;
import com.example.myui.adapter.RightAdapter;
import com.example.myui.model.ModelType;
import com.example.myui.model.ProDodel;

import java.util.ArrayList;

public class ListAndGrideActivity extends AppCompatActivity {


    private ArrayList<String> strings;
    private ArrayList<ModelType> mDatas;
    private ArrayList<ProDodel> proDodels;
    private static final String TAG = ListAndGrideActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_and_gride);
        initData();
        initView();
    }

    private void initData() {
        strings = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            strings.add("item :" + i);
        }

        mDatas = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            ModelType modelType = new ModelType();
            modelType.setTitle("title" + i);
            proDodels = new ArrayList<>();
            for (int j = 0; j < 20; j++) {
                ProDodel proDodel = new ProDodel();
                proDodel.setSubTitle("subTitle" + i);
                proDodels.add(proDodel);
            }
            modelType.setSubTitle(proDodels);
            mDatas.add(modelType);

        }
        Log.i(TAG, "initData: " + mDatas.size());

    }

    private void initView() {
        RecyclerView recyclerviewLeft = findViewById(R.id.recyclerview_left);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(ListAndGrideActivity.this, LinearLayoutManager.VERTICAL, false);
        recyclerviewLeft.setLayoutManager(linearLayoutManager);
        LeftAdapter leftAdapter = new LeftAdapter(ListAndGrideActivity.this, R.layout.item_title, strings);
        recyclerviewLeft.setAdapter(leftAdapter);

        RecyclerView recyclerviewRight = findViewById(R.id.recyclerview_right);
        recyclerviewRight.setLayoutManager(new GridLayoutManager(this, 3));
        RightAdapter rightAdapter = new RightAdapter(ListAndGrideActivity.this, R.layout.item_product, mDatas);
        recyclerviewRight.setAdapter(rightAdapter);
    }
}
